package com.qumitech.visualnovel.controller.rest;

import com.qumitech.visualnovel.component.annotation.RequireWhiteList;
import com.qumitech.visualnovel.model.common.BaseRsp;
import com.qumitech.visualnovel.model.common.ResultEnum;
import com.qumitech.visualnovel.pubdef.dto.amount.AmountQueryDTO;
import com.qumitech.visualnovel.pubdef.dto.im.ChatGroupAdminRecordQueryDTO;
import com.qumitech.visualnovel.pubdef.dto.im.ChatGroupForbidDTO;
import com.qumitech.visualnovel.pubdef.dto.im.ImChatGroupAdminQueryDTO;
import com.qumitech.visualnovel.pubdef.dto.im.ImUserChatGroupAdminQueryDTO;
import com.qumitech.visualnovel.service.social.SocialRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: ywxie
 * @Date: 2019/7/12 15:10
 * @Description:
 */

@RestController
@RequestMapping("/api/im")
public class ImController {

    @Autowired
    private SocialRelationService socialRelationService;

    @GetMapping("/relation/apply/num")
    public BaseRsp getUserRelationApplyNum(AmountQueryDTO amountQueryDTO){
        AmountQueryDTO dto = new AmountQueryDTO(amountQueryDTO.getUid(), amountQueryDTO.getStartTime(), amountQueryDTO.getEndTime());
        Map<String, String> paramMap = new HashMap<>();
        if (dto.getUid() != null){
            paramMap.put("account_id", amountQueryDTO.getUid());
        }
        if (dto.getStartTime() != null){
            paramMap.put("start_time", amountQueryDTO.getStartTime());
        }
        if (dto.getEndTime() != null){
            paramMap.put("end_time", amountQueryDTO.getEndTime());
        }
        return new BaseRsp(ResultEnum.SUCCESS, socialRelationService.getUserRelationApplySum(paramMap));
    }


    @RequireWhiteList
    @GetMapping("/chatgroup")
    public BaseRsp listChatGroup(ImChatGroupAdminQueryDTO queryDTO){
        return socialRelationService.listChatGroup(queryDTO);
    }

    @RequireWhiteList
    @GetMapping("/chatgroup/{group_id}/member")
    public BaseRsp listUserChatGroup(@PathVariable("group_id") String groupId, ImUserChatGroupAdminQueryDTO queryDTO){
        queryDTO.setGroupId(groupId);
        return socialRelationService.listUserChatGroup(queryDTO);
    }

    @RequireWhiteList
    @GetMapping("/chatgroup/forbid")
    public BaseRsp listChatGroupAdminRecord(ChatGroupAdminRecordQueryDTO queryDTO){
        return socialRelationService.listChatGroupAdminRecord(queryDTO);
    }

    @RequireWhiteList
    @PutMapping("/chatgroup/forbid")
    public BaseRsp forbidChatGroup(@RequestBody ChatGroupForbidDTO forbidDTO){
        return socialRelationService.forbidChatGroup(forbidDTO);
    }
}
